﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityModel;
using Common;

namespace Services
{
    public class ArticleService
    {
        #region***属性数据***

        ShopDbEntities bdContext = DbContextHelper.GetCurrentDbContext();

        #endregion

        #region 获取文章

        /// <summary>
        /// 获取所有文章分类
        /// </summary>
        /// <returns></returns>
        ///  PagedList<Category>
        ///  
        public IQueryable<Article> GetAllList()
        {
            ShopDbEntities bdContext = DbContextHelper.GetCurrentDbContext();
            return bdContext.Articles.OrderByDescending(c => c.Id);
        }

        #endregion

        #region 获取所有文章分类

        /// <summary>
        /// 获取所有显示文章分类
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Article> GetList()
        {
            return bdContext.Articles.Where(c => c.Status == (int)EnumModel.Status.Show).OrderByDescending(c => c.DisplayOrder);
        }
        #endregion

        #region 新增数据

        public void Create(Article model)
        {
            bdContext.Articles.AddObject(model);
            bdContext.SaveChanges();
        }
        #endregion

        #region 根据分类获取文章
        public IQueryable<Article> GetListByCategoryId(int categoryId)
        {
        
            return bdContext.Articles.Where(a => a.ArticleTypeId == categoryId);
        }
        #endregion

        #region   GetModel
        public Article GetModel(int id)
        {
            return bdContext.Articles.Include("ArticleType").FirstOrDefault(a => a.Id == id);

        }
        #endregion
    }
}
